//
//  AboutCategoryViewController.m
//  BosidengIphone
//
//  Created by  on 11-12-29.
//  Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//

#import "AboutCategoryViewController.h"
#import "BrandData.h"

@implementation AboutCategoryViewController
@synthesize brands;
@synthesize brandList;
@synthesize delegate;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        //self.brands = [BrandData getAllItems];
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)dealloc {
    self.delegate = nil;
    [brandList release];
    [brands release];
    [super dealloc];
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    brandList.dataSource = self;
    brandList.delegate = self;
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark -
#pragma mark Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return [brands count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"BrandsCellIdentifier";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.textLabel.textAlignment = UITextAlignmentCenter;
        cell.textLabel.font=[UIFont systemFontOfSize:12];
        cell.textLabel.textColor=[UIColor colorWithRed:1 green:1 blue:1 alpha:1];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }
    // Configure the cell...
	NSUInteger row = [indexPath row];
	BrandData *data = [brands objectAtIndex:row];
	
	cell.textLabel.text = data.name;
    return cell;
}

#pragma mark -
#pragma mark Table view delegate

- (void)hiddenMenuAnimation:(UIView*)view {
	[UIView beginAnimations:nil context:nil];
	[UIView setAnimationDuration:1];
	[UIView setAnimationDelay:0.0];
    CGAffineTransform transform = CGAffineTransformMakeTranslation(0, -416);
    view.transform = transform;
	[UIView commitAnimations];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSUInteger rowId = [indexPath row];
    if (delegate) {
        BrandData *data = [brands objectAtIndex:rowId];
        [delegate changeViewController:data];
    }
    [self hiddenMenuAnimation:self.view];
}

- (IBAction)close:(id)sender {
    [self hiddenMenuAnimation:self.view];
}

@end
